package com.lxw.nonghe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxw.nonghe.entity.Role;
import com.lxw.nonghe.mapper.RoleMapper;
import com.lxw.nonghe.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author lxw
 * @since 2025-04-17
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Override
    public Role getRoleById(Long roleId) {
        return this.getById(roleId);
    }
    @Override
    public Page<Role> getRolePage(int current, int size, String roleName) {
        Page<Role> page = new Page<>(current,size);
        return (Page<Role>) this.baseMapper.selectRolePage(page,roleName);
    }

    @Override
    public Role getRoleByRoleName(String roleName) {

        return this.lambdaQuery().eq(Role::getRoleName,roleName).one();
    }

    @Override
    public Page<Role> queryRoles(Role queryRole, int current, int size) {
        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
        if(queryRole.getRoleId() != null){
            wrapper.eq(Role::getRoleId,queryRole.getRoleId());
        }
        if (queryRole.getRoleName() != null){
            wrapper.eq(Role::getRoleName,queryRole.getRoleName());
        }
        if(queryRole.getRoleDesc() != null){
            wrapper.eq(Role::getRoleDesc, queryRole.getRoleDesc());
        }
        Page<Role> page = new Page<>(current,size);
        return this.page(page,wrapper);
    }
}
